package com.ruoyi.project.zxbd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.common.zx.PageData;
import com.ruoyi.project.zxbd.service.impl.BdGoodsServiceImpl;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 物料产品Controller
 *
 * @author zx
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/zxbd/goods")
public class BdGoodsController extends BaseController {
    @Autowired
    private BdGoodsServiceImpl bdGoodsService;

/**
 * 查询物料产品列表
 */
@PreAuthorize("@ss.hasPermi('zxbd:goods:list')")
@GetMapping("/list")
    public TableDataInfo list() {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = bdGoodsService.selectBdGoodsList(pd);
        return getDataTable(list);
    }

    /**
     * 导出物料产品列表
     */
    @PreAuthorize("@ss.hasPermi('zxbd:goods:export')")
    @Log(title = "物料产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageData pd) {
        List<PageData> list = bdGoodsService.selectBdGoodsList(pd);
        ExcelUtil<PageData> util = new ExcelUtil<PageData>(PageData. class);
        util.exportExcel(response, list, "物料产品数据");
    }

    /**
     * 获取物料产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxbd:goods:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code) {
        return success(bdGoodsService.selectBdGoodsByCode(code));
    }

    /**
     * 新增物料产品
     */
    @PreAuthorize("@ss.hasPermi('zxbd:goods:add')")
    @Log(title = "物料产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PageData pd) {
        return toAjax(bdGoodsService.insertBdGoods(pd));
    }

    /**
     * 修改物料产品
     */
    @PreAuthorize("@ss.hasPermi('zxbd:goods:edit')")
    @Log(title = "物料产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PageData pd) {
        return toAjax(bdGoodsService.updateBdGoods(pd));
    }

    /**
     * 删除物料产品
     */
    @PreAuthorize("@ss.hasPermi('zxbd:goods:remove')")
    @Log(title = "物料产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes) {
        return toAjax(bdGoodsService.deleteBdGoodsByCodes(codes));
    }
}
